package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.ITMSWebServiceForChangeMode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zsf
 * @date 2018/3/6 9:15
 * @desc 宽带上网业务更改模式——桥接改路由
 */

public class ITMS_Broadband_Business_Change_Mode implements WorkInterFace {


	protected static Log log = LogFactory.getLog(ITMS_Broadband_Business_Change_Mode.class);


	@Override
	public String getName() {
		return "宽带上网业务更改模式——桥接改路由";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[1];
		in[0]=new Attr("sn","用户宽带账号(两个参数选填一个)", AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[3];
		out[0]=new Attr("RetMsg", "返回的msg", AttrType.TYPE_String, true);
		out[1]=new Attr("RetCode", "返回code 1:成功，0:失败", AttrType.TYPE_Int, true);
		out[2] = new Attr("show", "日志输出", AttrType.TYPE_String, true);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {

		ITMSWebServiceForChangeMode itmsWebServiceForChangeMode = new ITMSWebServiceForChangeMode();
		AttrsIn attrsIn=new AttrsIn();
		Map<String,Object> map=new HashMap<String, Object>();
		attrsIn.setFunctionName("tz:itmsBroadbandBusinessChangeMode");
		String sn = (String) data.get("sn");
		String mode = "1";
		attrsIn.setRequestMessage("<sn>"+sn+"</sn><mode>"+mode+"</mode>");
		String result = itmsWebServiceForChangeMode.WebServiceInit(attrsIn);
		result = result.substring(result.indexOf("<return>")+9,result.indexOf("</return>")-1);
		String[] arg = result.split(",");
		map.put("RetMsg",result.substring(arg[0].indexOf("=")+1));
		map.put("RetCode",result.substring(arg[1].indexOf("=")+1));
		map.put("show",result.substring(arg[0].indexOf("=")+1));
		return map;
	}



}
